# 读取test_data.jsonl后，读取其中"need_check"为true和false的数量，进行打印
import json
import os
from collections import Counter

# 初始化计数器
true_count = 0
false_count = 0

# 用于统计文件类型
file_types = Counter()

# 读取jsonl文件
with open('../data/research_data/RQ2/train_data.jsonl', 'r', encoding='utf-8') as file:
    for line in file:
        data = json.loads(line)
        if data.get('need_check') is True:
            true_count += 1
        elif data.get('need_check') is False:
            false_count += 1
            
        # 分析文件类型
        if 'after_file' in data and 'filename' in data['after_file']:
            filename = data['after_file']['filename']
            # 获取文件扩展名
            _, ext = os.path.splitext(filename)
            if ext:
                file_types[ext] += 1
            else:
                file_types['no_extension'] += 1

# 打印结果
print(f'need_check为true的数量: {true_count}')
print(f'need_check为false的数量: {false_count}')

# 打印文件类型统计
print('\n文件类型统计:')
for file_type, count in sorted(file_types.items(), key=lambda x: x[1], reverse=True):
    print(f'{file_type}: {count}')
